import React from 'react';
import useHistory from '../hooks/useHistory';

const ALink = ({children})=>{
  return <a>{children}</a>
}
type LinkProps<T extends React.ElementType>  = {
  children?: React.ReactNode,
  Tag: T,
  to: string
}& React.ComponentProps<T>
const Link =<T extends React.ElementType = typeof ALink>({ 
  Tag = ALink as unknown as T,
  children, to ,
...rest
}: LinkProps<T>) => {
  const nav = useHistory()
  const _onClick = () => {
    nav.push(to)

  }
  return (<Tag type='link' onClick={_onClick} {...rest}>{children}</Tag>)
}
export default Link